package com.holyshit.exam.utils;

import com.alibaba.fastjson.JSON;

import org.json.JSONObject;

import java.util.List;

public class JsonUtils {

    public static <T> T parseObject(String jString, Class<T> clz) {
        try {
            return JSON.parseObject(jString, clz);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    public static <T> List<T> parseArray(String jString, Class<T> clz) {
        try {
            return JSON.parseArray(jString, clz);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String getJsonString(JSONObject json, String key) {
        try {
            return json.getString(key);
        } catch (Exception e) {
            return null;
        }
    }

    public static String getJsonString(String json, String key) {
        try {
            return getJsonString(new JSONObject(json), key);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
